﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using System.Data;
using System.Xml;

public partial class ws_SP_PermDocs_ApproveItem : WSPageBase
{

    #region Page Events

    protected override void OnPreInit(EventArgs e)
    {
        base.OnPreInit(e);
        // Enabled trace in code
        this.Context.Trace.IsEnabled = false;
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);
        XmlDocument xReturn = getXML();
        Response.ContentType = "text/xml";
        Response.Write(xReturn.OuterXml);
    }

    #endregion

    #region Data

    public XmlDocument getXML()
    {
        XmlDocument xReturn = new XmlDocument();

        DataTable tbl = new DataTable("tbl");
        Ko2.Portal.SP_List.SPList_PermDocs o = new Ko2.Portal.SP_List.SPList_PermDocs();
        Exception err = null;
        string newstatusStr = Request.Params["newstatus"];
        if (String.IsNullOrEmpty(newstatusStr))
            return xReturn;
        Ko2.Portal.SP_List.SPList_PermDocs.DocStatus docstatus;
        // Черновик , Ожидают_утверждения, Утвержден
        if (newstatusStr == "1")
            docstatus = Ko2.Portal.SP_List.SPList_PermDocs.DocStatus.Черновик;
        else if (newstatusStr == "2")
            docstatus = Ko2.Portal.SP_List.SPList_PermDocs.DocStatus.Ожидают_утверждения;
        else if (newstatusStr == "3")
            docstatus = Ko2.Portal.SP_List.SPList_PermDocs.DocStatus.Утвержден;
        else
            return xReturn;

        if (intID != -1 && docstatus != null)
        {
            err = o.ApproveOrRegectItem(intID, docstatus);

            tbl = new DataTable("Result");

            tbl.Columns.Add("ID", typeof(string));
            tbl.Columns[0].Caption = "ID";
            tbl.Columns.Add("Name", typeof(string));
            tbl.Columns[1].Caption = "Name";

            if (err == null)
            {
                DataRow r = tbl.NewRow();
                r[0] = intID.ToString();
                r[1] = newstatusStr;
                tbl.Rows.Add(r);
            }
            else
            {
                DataRow r = tbl.NewRow();
                r[0] = "-1000";
                r[1] = "Ошибка операции.";
                tbl.Rows.Add(r);
            }

            MakeXML(ref xReturn, ref tbl, ref err);
        }
        return xReturn;
    }

    #endregion

}
